In [15]:
def compute_feets(text):
l, w, h = [int(v) for v in text.split('x')]
f1 = l*w
f2 = w*h
f3 = h*l
return 2*(f1 + f2 + f3) + min(f1, f2, f3)
In [8]:
# Test examples
compute_feets("1x1x10")
Out[8]:
In [16]:
# Real input
with open('day2/input.txt', 'rt') as gifts:
total_feets = 0
for gift in gifts:
total_feets += compute_feets(gift.rstrip())
print("They should order {} square feet of wrapping paper".format(total_feets))
In [17]:
def compute_ribbon(text):
l, w, h = [int(v) for v in text.split('x')]
return 2*(l + w + h - max(l, w, h)) + l*w*h
In [18]:
# Test examples
compute_ribbon("2x3x4")
Out[18]:
In [19]:
# Real input
with open('day2/input.txt', 'rt') as gifts:
total_ribbon = 0
for gift in gifts:
total_ribbon += compute_ribbon(gift.rstrip())
print("They should order {} feet of ribbon".format(total_ribbon))